package com.atguigu.gmall.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.service.ManagerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;

@Api(tags = "商品SKU接口")
@RestController
@RequestMapping("admin/product")
public class SkuManageController {
    @Autowired
    private ManagerService manageService;


    @GetMapping("spuImageList/{spuId}")
    @ApiOperation(value = "根据spuId获取spu图片列表", notes = "保存sku时 做选择用")
    public Result getSpuImageList(@PathVariable("spuId") Long spuId) {
        Result result = manageService.getSpuImageList(spuId);
        return result;
    }

    @GetMapping("spuSaleAttrList/{spuId}")
    @ApiOperation(value = "根据spuId获取销售属性 与销售属性值", notes = "保存sku时 做选择用")
    public Result getSpuSaleAttrList(@PathVariable("spuId") Long spuId) {
        Result result = manageService.getSpuSaleAttrList(spuId);
        return result;
    }

    @PostMapping("saveSkuInfo")
    @ApiOperation(value = "根据spuId获取销售属性 与销售属性值", notes = "保存sku时 做选择用")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo) {
        manageService.saveSkuInfo(skuInfo);
        return Result.ok(skuInfo);
    }


    @GetMapping("/list/{pageNum}/{pageSize}")
    @ApiOperation(value = "根据skuId获取sku信息", notes = "保存sku时 做选择用")
    public Result list(@PathVariable("pageNum") Long pageNum,
                       @PathVariable("pageSize") Long pageSize,
                       @RequestParam Long category3Id) {
        Page<SkuInfo> page = new Page<>(pageNum, pageSize);
        Result result = manageService.list(page, category3Id);

        return result;
    }

    @GetMapping("/getSkuInfo/{skuId}")
    @ApiOperation(value = "根据skuId获取sku信息", notes = "保存sku时 做选择用")
    public Result getSkuInfo(@PathVariable("skuId") Long skuId) {
        Result result = manageService.getSkuInfo(skuId);
        return result;
    }


    @GetMapping("/onSale/{skuId}")
    @ApiOperation(value = "根据skuId获取sku信息", notes = "保存sku时 做选择用")
    public Result onSale(@PathVariable("skuId") Long skuId) {
        Result result = manageService.onSale(skuId);
        return result;
    }
    @GetMapping("/cancelSale/{skuId}")
    @ApiOperation(value = "根据skuId获取sku信息", notes = "保存sku时 做选择用")
    public Result cancelSale(@PathVariable("skuId") Long skuId) {
        Result result = manageService.cancelSale(skuId);
        return result;
    }
}
